﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_AdminAuditing : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindExamTimeList();
            bindDateTable();
        }
    }
    private void bindExamTimeList()
    {
        DataTable dt = Exam.ExamTime_GetCurrExamList();
        BSUtility.BindListControl(List_ExamAllName, dt, "EmAllName", "TimeID");

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        bindDateTable();
    }
    private void bindDateTable()
    {
        if (List_ExamAllName.SelectedValue != null)
        {
            DataTable dt = Exam.getWillRecord(List_ExamAllName.SelectedValue.ToString());
            gv.DataSource = dt;
            gv.DataBind();
        }
    }
    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv.PageIndex = e.NewPageIndex;
        bindDateTable();
    }
    protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.CompareTo("Accept") == 0) 
        {


            int index = ((GridViewRow)((LinkButton)(e.CommandSource)).Parent.Parent).RowIndex;
            string applyId = gv.DataKeys[index].Values[0].ToString().Trim();
            GridViewRow row = gv.Rows[index];
            string newRankName = row.Cells[4].Text;
            if (Exam.updateApplyRank(applyId, newRankName) && Exam.updateRecordState(applyId,"2"))
            {
                Response.Redirect(BSUtility.mainUrl + "admin/AdminAudit.aspx");
            }
        }
        else if (e.CommandName.CompareTo("Deny") == 0)
        {
            int index = ((GridViewRow)((LinkButton)(e.CommandSource)).Parent.Parent).RowIndex;
            string applyId = gv.DataKeys[index].Values[0].ToString().Trim();
            GridViewRow row = gv.Rows[index];
            if (Exam.updateRecordState(applyId,"2"))
            {
                Response.Redirect(BSUtility.mainUrl + "admin/AdminAudit.aspx");
            }
        }
    }
}